# 商品在页面中的排名
import pandas as pd

def generate_item_rank_data():
    # 定义分类排名映射
    category_rank_map = {
        '服务商': 1,
        '需求': 2,
        '产品': 3
    }
    
    # 定义各分类下的商品ID列表
    category_items = {
        '服务商': [
            "1752201132575887362", "1745393239782543361", "1747883569961246721",
            "1746723605406294018", "1747545536628006913", "1747549630780416002",
            "1748176276113858562", "1752547440390115330", "1762764208850960386",
            "1777220425443643393"
        ],
        '需求': [
            "1945698599953195010", "1943850179177177089", "1799254413328060418",
            "1792088154094243841", "1784169542658363393", "1784143514028281858",
            "1784180218621661185", "1784145154827423745", "1784144143995965442",
            "1784142763507912706"
        ],
        '产品': [
            "1940341982390190081", "1914162459386523650", "1772159794201956354",
            "1914165353569529857", "1783054785324613633", "1760648919532113921",
            "1752300430601379842", "1752692190192230402", "1752166454800834561",
            "1751877693189808129"
        ]
    }
    
    # 生成排名数据
    rank_data = []
    for category, item_ids in category_items.items():
        # 按ID降序排序
        sorted_ids = sorted(item_ids, key=lambda x: int(x), reverse=True)
        
        # 为每个商品分配排名
        for position, item_id in enumerate(sorted_ids, start=1):
            rank_data.append({
                'content_id': item_id,
                'category_rank': category_rank_map[category],
                'position_rank': position
            })
    
    # 转换为DataFrame并返回
    return pd.DataFrame(rank_data)

# 生成并存储排名数据
item_rank_df = generate_item_rank_data()
# 保存为CSV格式（替换Parquet格式）
item_rank_df.to_csv('/data/GuoCu_data/processed_data/feature/item/user_item_inter_rank.csv', index=False)

# 读取并打印存储的内容
import pandas as pd
stored_df = pd.read_csv('/data/GuoCu_data/processed_data/feature/item/user_item_inter_rank.csv')
print("存储的内容预览:")
print(stored_df.head())  # 打印前5行
print("\n数据形状:", stored_df.shape)
# 示例：保存为CSV文件
# item_rank_df.to_csv('item_rank_data.csv', index=False)
# 示例：如果需要在其他地方使用，可以将DataFrame存储为模块变量
# ITEM_RANK_DATA = item_rank_df